﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace Medicalsystem.MCP.FormDesigner.Property
{
    /// <summary>
    /// 弹出式对话框编辑
    /// </summary>
    public class ContentEditorModal : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                return UITypeEditorEditStyle.Modal;
            }

            return base.GetEditStyle(context);
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;

            if (context != null && context.Instance != null && provider != null)
            {
                editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (editorService != null && context.Instance is GetProperty)
                {
                    value = (context.Instance as GetProperty).ShowEditor(context.PropertyDescriptor.PropertyType, context.PropertyDescriptor.Name, value);
                }
            }

            return value;
        }
    }
}